// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import NutUI from '@nutui/nutui';
import '@nutui/nutui/dist/nutui.css';
import qs from 'qs'
import axios from 'axios';
import helper from "./utils/helper";
import api from "./utils/api";
import clipboard from 'clipboard';
import { Loading,Dialog } from 'vant';

import VueI18n from 'vue-i18n';


import 'vant/lib/loading/style';
import 'vant/lib/dialog/style';


// 请求拦截
axios.interceptors.request.use(config => {
  const token = helper.getToken();
  if (token) {
    // 在发起请求前，给所有请求的头部添加token
    config.headers.common['Authorization'] = "Bearer " + token;
    config.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
  }
  
  return config;
}, error => {
  // 对请求失败做处理
  return Promise.reject(error);
})
axios.interceptors.response.use(res => {
  // 对响应数据做处理
  // console.log("对响应数据做处理")
  const code = res.data.code;
  /*if (code === -10086) {
    // 判断res.data.res_code 是否是401 如果是则跳转到登录，如果不是则正常返回
    helper.forgetToken();
    location.href="/#/logout";
    return false;
  }*/
  return res;
}, error => {
  // 对响应错误做处理
  return Promise.reject(error);
})

axios.defaults.crossDomain=true;
axios.defaults.withCredentials = true;


Vue.prototype.$qs = qs;
Vue.prototype.$axios = axios;
Vue.prototype.$helper = helper;
Vue.prototype.$api_url = api;
Vue.prototype.$clipboard = clipboard;
Vue.prototype.$dialog2 = Dialog;

NutUI.install(Vue);

Vue.config.productionTip = false;
Vue.use(VueI18n);

axios.get(api.user+'/get_config').then((res)=>{
    localStorage.setItem('config_bg',qs.stringify(res.data));
    document.title = res.data.title
})

const i18n = new VueI18n({
    locale: 'en',  // 语言标识
    messages: {
        'zh': require('./utils/lang/zh'),
        'en': require('./utils/lang/en'),
		'hi': require('./utils/lang/hi'),
		'id': require('./utils/lang/id'),
		'cht': require('./utils/lang/cht')
    }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  i18n,
  components: { App },
  template: '<App/>'
})

